﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using System.Windows.Controls;
using System.Collections.Specialized;

namespace LightSwitchApplication
{
    public partial class ItemAttributesEditGrid
    {        
        partial void ItemAttributesEditGrid_Created()
        {
            // Write your code here.
            this.cboItem = this.DataWorkspace.LSWData.Items.Where(o => o.ItemID == this.ItemID).SingleOrDefault();
        }

        partial void cboItem_Changed()
        {
            if(!this.ItemID.Equals(this.cboItem.ItemID))
                this.ItemID = this.cboItem.ItemID; 
        }

        partial void ItemAttributes_Changed(NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                if (e.NewItems.Count > 0)
                    (e.NewItems[0] as ItemAttribute).Item = this.cboItem;
            }
        }
    }
}
